<extend name="_layout/main"/>
<block name="head">
    <style>
        .attachments img {
            cursor: pointer;
            max-width: 200px;
        }
    </style>
</block>
<block name="content">
    <div class="page-content">
        <!-- Page Breadcrumb -->
        <div class="page-breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>
                    <a href="{:U('dashboard/index')}">系统首页</a>
                </li>
                <li>
                    <a href="{:U('user/index')}">联盟商家申请</a>
                </li>
                <li class="active">记录详情</li>
            </ul>
        </div>
        <!-- /Page Breadcrumb -->

        <!-- Page Body -->
        <div class="page-body">
            <div class="row">
                <div class="col-xs-12 col-md-12">
                    <div class="tabbable">
                        <ul class="nav nav-tabs" id="myTab">
                            <li class="active">
                                <a href="javascript:;" aria-expanded="true">记录详情</a>
                            </li>
                        </ul>

                        <div class="tab-content">
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td width="150">ID：</td>
                                    <td>{$result.id}</td>
                                </tr>
                                <tr>
                                    <td>用户：</td>
                                    <td>{$users[$result['user_id']]['nickname']}</td>
                                </tr>
                                <tr>
                                    <td>商家：</td>
                                    <td>{$result.supplier_name}</td>
                                </tr>
                                <tr>
                                    <td>身份证：</td>
                                    <td>
                                        {$result.id_number}
                                    </td>
                                </tr>
                                <tr>
                                    <td>手机号码：</td>
                                    <td><label>{$result.mobile}</label></td>
                                </tr>
                                <tr>
                                    <td>固定电话：</td>
                                    <td><span>{$result.telephone} </span></td>
                                </tr>
                                <tr>
                                    <td>行业：</td>
                                    <td>{$result.industry_name}</td>
                                </tr>
                                <tr>
                                    <td>店铺地址：</td>
                                    <td>{$result.position} {$result.address}</td>
                                </tr>
                                <tr>
                                    <td>提交时间：</td>
                                    <td>{$result.created_at|format_time}</td>
                                </tr>
                                <tr>
                                    <td>状态：</td>
                                    <td>{:applyStatus($result['status'])}</td>
                                </tr>
                                <neq name="result['status']" value="0">
                                    <tr>
                                        <td>审核人：</td>
                                        <td>
                                            {$result.checker}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>处理时间：</td>
                                        <td>{$result.deal_at|format_time}</td>
                                    </tr>
                                </neq>
                                <tr>
                                    <td>商家介绍：</td>
                                    <td>{$result.introduce}</td>
                                </tr>

                                <eq name="result['status']" value="1">
                                    <tr>
                                        <td>拒绝原因：</td>
                                        <td>{$result.refuse_msg}</td>
                                    </tr>
                                </eq>
                                <tr class="attachments">
                                    <td>上传附件：</td>
                                    <td>
                                        <notempty name="result['business_license']">
                                            <img src="{$result.business_license}"/>
                                        </notempty>
                                        <notempty name="result['organization_code']">
                                            <img src="{$result.organization_code}"/>
                                        </notempty>
                                        <notempty name="result['id_face']">
                                            <img src="{$result.id_face}"/>
                                        </notempty>
                                        <notempty name="result['id_back']">
                                            <img src="{$result.id_back}"/>
                                        </notempty>
                                    </td>
                                </tr>
                                <eq name="result['status']" value="0">
                                    <tr>
                                        <td>拒绝原因：</td>
                                        <td>
                                            <div class="form-group">
                                                <div class="col-xs-4">
                                                    <textarea class="form-control" rows="5" id="refuse_msg"
                                                              name="refuse_msg"></textarea>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </eq>
                                <tr>
                                    <td></td>
                                    <td>
                                        <a href="javascript:;" onclick="history.go(-1)" class="btn btn-default shiny"><<返回</a>
                                        <eq name="result['status']" value="0">
                                        <a href="javascript:void(0);" class="btn btn-success shiny check-btn" data-type="ok" data-id="{$result.id}">通过审核</a>
                                        <a href="javascript:void(0);" class="btn btn-darkorange shiny check-btn" data-type="cancel" data-id="{$result.id}">审核失败</a>
                                        </eq>
                                    </td>
                                </tr>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="horizontal-space"></div>

                </div>
            </div>

        </div>
        <!-- /Page Body -->
    </div>

</block>
<block name="footer">
    <script>
        $(".attachments img").click(function () {
            var img = $(this).attr('src');
            var html = '<div style="padding-top:30px;"> <img src="' + img + '" style="width:100%;" /></div>';
            bootbox.dialog({
                message: html,
            });
        })

        $(document).on('click', ".check-btn", function(){
            var _type = $(this).data('type');
            var _id = $(this).data('id');
            if(isNaN(_id)){
                return;
            }
            var data = {
                id:_id,
            };
            if(_type == 'ok'){
                data.status = 2;
            }else if(_type == 'cancel'){
                var msg = $("#refuse_msg").val();
                if(!msg || msg==''){
                    tips('请输入拒绝的原因','danger');
                    return;
                }
                data.status = 1;
                data.msg = msg;
            }

            $.post("{:U('Supplier/ok')}", data, function(xdata){
                console.log(JSON.stringify(xdata));
                if(xdata.status == 'success'){
                    document.location.reload();
                }else{
                    tips(xdata.message);
                }
            },'json');
        })
    </script>
</block>
